﻿@{
   Validation.RequireField("Username","You didn't enter Username!");
   Validation.RequireField("Password","You didn't enter Password!");


   var db = Database.Open("CvProjectDatabase");
   var Username = Request.Form["Username"];
   var Password = Request.Form["Password"];
   var isDeleted = "False";
   var selectQuery = "SELECT * FROM Users WHERE IsDeleted = @0";
   var selectedData = db.Query(selectQuery, isDeleted );
   var grid = new WebGrid(source: selectedData);


   if(IsPost && Validation.IsValid()){
   foreach (var user in selectedData){
       if(user.Username == Username && user.Password == Password){
           Session["u.Username"] = user.Username;
           if(user.isAdmin){
               Session["u.isAdmin"] = user.isAdmin;

           } else{
               Session["u.isAdmin"] = "False";
           }
           Response.Redirect("Index.cshtml");

       }

   }

   }
}

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        @Html.ValidationSummary()
        
                <h2>Login</h2>
            
                    <form method="post">
                        <label for="Username">Username</label>
                       
                            <input type="text" id="Username" name="Username" value="@Request.Form["u.Username"]">
                            @Html.ValidationMessage("Username")
                        
                        <label for="Password">Password</label>
                        
                            <input type="password" id="Password" name="Password">
                            @Html.ValidationMessage("Password")
                    
                        
                            <button type="submit" class="btnLogin">Login</button> 
                       
                    </form>
              


    </body>
</html>
